﻿using Alos.Common;
using Alos.Entity;
using Alos.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;


namespace Alos.LanClass.Api
{
    /// <summary>
    /// 课堂学生标记（点赞）
    /// </summary>
    public class ReClassSignController : ApiController
    {
        IReClassSignService ReClassSignService;
         
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_ReClassSignService"></param>
        public ReClassSignController(IReClassSignService _ReClassSignService)
        {
            ReClassSignService = _ReClassSignService;
        }
        /// <summary>
        /// 根据备课编号获取当前该课堂上学生标记
        /// </summary>
        /// <param name="id">备课编号</param>
        /// <param name="ReType">类型  上课点评0 ， 结束上课评论1</param>
        /// <returns></returns>
        [HttpGet]
        [Route("api/ReClassSign/GetReClassSign")]
        public async Task<JsonRtn<List<ReClassSign>>> GetReClassSign(int id, int ReType)
        {
            var jsRtn = new JsonRtn<List<ReClassSign>>();
            jsRtn.data = await ReClassSignService.GetReClassSign(id, ReType);                               
            return jsRtn;
        }
        /// <summary>
        /// 添加学生课堂标记
        /// </summary>
        /// <param name="data">学生课堂标记</param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/ReClassSign/CreatReClassSign")]
        public JsonRtn<dynamic> CreatReClassSign([FromBody]dynamic data)
        {
            var jsRtn = new JsonRtn<dynamic>();
            foreach (ReClassSign reClassSign in data)
            {
                jsRtn.message = ReClassSignService.CreatReClassSign(reClassSign) > 0 ? jsRtn.message : "添加失败";
            }
            return jsRtn;             
        }
        /// <summary>
        /// 根据备课编号,学生ID SignContent ReType删除学生课堂标记
        /// </summary>
        /// <param name="data">备课编号,学生ID SignContent ReType</param>
        /// <returns></returns>
        [HttpPost]
        [Route("api/ReClassSign/DeleteReClassSign")]
        public JsonRtn<dynamic> DeleteReClassSign([FromBody]dynamic data)
        {
            var jsRtn = new JsonRtn<dynamic>();
            foreach (ReClassSign reClassSign in data)
            {
                jsRtn.message = ReClassSignService.DeleteReClassSign((int)reClassSign.LessionID, (int)reClassSign.StudentID, (int)reClassSign.SignContent, (int)reClassSign.ReType) > 0 ? "true" : "false";
            }
            return jsRtn; 
        }
    }
}
